package com.zhang.publicproject.common.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/8/30.
 */

public class MapUtils {
    public static String getMapKey(Map<Long, Integer> map) {


        // 第三种：推荐，尤其是容量大时
        StringBuilder sb = new StringBuilder();
        System.out.println(map.size());

        String keyStrTEM = "";
        if (map.size() > 1) {
            for (Map.Entry<Long, Integer> entry : map.entrySet()) {

                sb.append(entry.getKey());
                sb.append(",");

            }
            String keyStr = sb.toString();
            keyStrTEM = keyStr.substring(0, keyStr.length() - 1);
            //return keyStrTEM;
        } else if (map.size() == 1) {
            for (Map.Entry<Long, Integer> entry : map.entrySet()) {

                keyStrTEM = entry.getKey() + "";
            }


        }


        return keyStrTEM;
    }

    public static String getMapValue(Map<Long, Integer> map) {


        // 第三种：推荐，尤其是容量大时
        StringBuilder sb = new StringBuilder();
        System.out.println(map.size());

        String keyStrTEM = "";
        if (map.size() > 1) {
            for (Map.Entry<Long, Integer> entry : map.entrySet()) {

                sb.append(entry.getValue());
                sb.append(",");

            }
            String keyStr = sb.toString();
            keyStrTEM = keyStr.substring(0, keyStr.length() - 1);
            // return keyStrTEM;
        } else if (map.size() == 1) {
            for (Map.Entry<Long, Integer> entry : map.entrySet()) {

                keyStrTEM = entry.getValue() + "";
            }


        }


        return keyStrTEM;
    }


    public static String getShopIdForMapValue(Map<String, Integer> map) {


        // 第三种：推荐，尤其是容量大时
        StringBuilder sb = new StringBuilder();
        System.out.println(map.size());

        String keyStrTEM = "";
        if (map.size() > 1) {
            for (Map.Entry<String, Integer> entry : map.entrySet()) {

                sb.append(entry.getValue());
                sb.append(",");

            }
            String keyStr = sb.toString();
            keyStrTEM = keyStr.substring(0, keyStr.length() - 1);
            //  return keyStrTEM;
        } else if (map.size() == 1) {
            for (Map.Entry<String, Integer> entry : map.entrySet()) {

                keyStrTEM = entry.getValue() + "";
            }


        }


        return keyStrTEM;
    }


    public static String getRemarkForMapValue(Map<String, String> map) {


        // 第三种：推荐，尤其是容量大时
        StringBuilder sb = new StringBuilder();
        System.out.println(map.size());

        String keyStrTEM = "";
        if (map.size() > 1) {
            for (Map.Entry<String, String> entry : map.entrySet()) {
                if (entry.getValue() == "") {
                    sb.append("1");
                    sb.append("@");
                } else {
                    sb.append(entry.getValue());
                    sb.append("@");
                }
            }
            String keyStr = sb.toString();
            keyStrTEM = keyStr.substring(0, keyStr.length() - 1);
            return keyStrTEM;
        } else if (map.size() == 1) {
            for (Map.Entry<String, String> entry : map.entrySet()) {

                keyStrTEM = entry.getValue() + "";
            }


        }


        return keyStrTEM;
    }

    public static String getDetailsIdForList(List<Long> list) {
        StringBuilder sb = new StringBuilder();
        String result = "";
        if (list.size() != 0) {

            for (int i = 0; i < list.size(); i++) {
                sb.append(list.get(i));
                sb.append(",");

            }
            String str = sb.toString();
            result = str.substring(0, str.length() - 1);

        } else if (list.size() == 1) {
            result = list.get(0) + "";

        }
        return result;
    }


    public static String getTimeCha(String timebegin, String timeend) {
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        String timeStr = "";
        Date d1 = null;
        try {
            d1 = df.parse(timebegin);
            Date d2 = df.parse(timeend);
            long diff = d1.getTime() - d2.getTime();//这样得到的差值是微秒级别

            long days = diff / (1000 * 60 * 60 * 24);

            long hours = (diff - days * (1000 * 60 * 60 * 24)) / (1000 * 60 * 60);

            long minutes = (diff - days * (1000 * 60 * 60 * 24) - hours * (1000 * 60 * 60)) / (1000 * 60);
            timeStr = "" + days + hours + minutes;

        } catch (ParseException e) {
            e.printStackTrace();
        }


        return timeStr;
    }

}
